package com.hylu.springboot.system.controller;

import com.hylu.springboot.system.pojo.po.MenuDO;
import com.hylu.springboot.system.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@Controller
public class LoginController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    MenuService menuService;
    /**
     * 主页
     *
     * @return
     */
    @GetMapping({"/index"})
    ModelAndView index() {
        ModelAndView mav = new ModelAndView("index");
        Map<MenuDO, List<MenuDO>> menuDOListMap = menuService.queryMenuDefault();
        mav.addObject("menuDOListMap",menuDOListMap);
        return mav;
    }

    /**
     * 首页（进入主页默认展示的第一个页面）
     *
     * @return
     */
    @GetMapping("/main")
    String main() {
        return "main";
    }

    /**
     * 拦截所有其他请求
     *
     * @param model
     * @return
     */
    @GetMapping({"/", ""})
    String welcome(Model model) {
        return "redirect:/index";
    }
}


